package com.baimawangzi.recovery.dao.impl;

import com.baimawangzi.recovery.dao.BaseDao;
import com.baimawangzi.recovery.util.dbutil.BeanHandler;
import com.baimawangzi.recovery.util.dbutil.DBConnection;
import com.baimawangzi.recovery.util.dbutil.QueryRunner;

import java.sql.Connection;
import java.util.List;

public abstract class  BaseDaoImpl<T> implements BaseDao<T> {
    public BaseDaoImpl() {
        this.clazz = Object.class;
        init();
    }
    //那个实体类的Dao
    protected Class clazz;
    protected Connection conn=null;
    protected QueryRunner queryRunner=null;
    protected void init(){
        conn = DBConnection.getConn();
        queryRunner = new QueryRunner(conn);
    }
    protected void destory(){
           DBConnection.close(conn);
    }
    @Override
    public List<T> map(String sql, Object[] obj) {
        List<T> os = queryRunner.query(sql, new BeanHandler<T>(clazz), obj);
        return os;
    }
}
